package com.martin.study.aop.test;

import com.martin.study.aop.bean.Order;
import com.martin.study.aop.bean.advice.MartinAroundAdvice;
import org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 周瑜
 */
@Configuration
public class BeanNameAutoProxyCreatorDemo {

	@Bean
	public Order order() {
		return new Order();
	}

	@Bean
	public MartinAroundAdvice martinAroundAdvice() {
		return new MartinAroundAdvice();
	}

	@Bean
	public BeanNameAutoProxyCreator beanNameAutoProxyCreator() {
		BeanNameAutoProxyCreator beanNameAutoProxyCreator = new BeanNameAutoProxyCreator();
		beanNameAutoProxyCreator.setBeanNames("or*");
		beanNameAutoProxyCreator.setInterceptorNames("martinAroundAdvice");
		beanNameAutoProxyCreator.setProxyTargetClass(true);
		return beanNameAutoProxyCreator;
	}

	public static void main(String[] args) {
		AnnotationConfigApplicationContext applicationContext =
				new AnnotationConfigApplicationContext(BeanNameAutoProxyCreatorDemo.class);

		Order order = applicationContext.getBean("order", Order.class);
		order.getItem();
	}
}
